Don't place html in alt/title attributes, especially with thumbnails
[lhc/web/wiklou.git] / includes / MessageCache.php
index a02bd62..ea7ae52 100755 (executable)
@@ -21,8 +21,7 @@ define( 'MSG_WAIT_TIMEOUT', 10);
  *
  * @package MediaWiki
  */
-class MessageCache
-{
+class MessageCache {
        var $mCache, $mUseCache, $mDisable, $mExpiry;
        var $mMemcKey, $mKeys, $mParserOptions, $mParser;
        var $mExtensionMessages = array();
@@ -30,7 +29,6 @@ class MessageCache
        var $mDeferred = true;
 
        function initialise( &$memCached, $useDB, $expiry, $memcPrefix) {
-               global $wgLocalMessageCache;
                $fname = 'MessageCache::initialise';
                wfProfileIn( $fname );
 
@@ -59,7 +57,7 @@ class MessageCache
                wfProfileOut( $fname );
        }
 
-       /** 
+       /**
         * Try to load the cache from a local file
         */
        function loadFromLocal( $hash ) {
@@ -69,10 +67,12 @@ class MessageCache
                if ( $wgLocalMessageCache === false ) {
                        return;
                }
-               
+
                $filename = "$wgLocalMessageCache/messages-$wgDBname";
 
+               wfSuppressWarnings();
                $file = fopen( $filename, 'r' );
+               wfRestoreWarnings();
                if ( !$file ) {
                        return;
                }
@@ -96,9 +96,11 @@ class MessageCache
                if ( $wgLocalMessageCache === false ) {
                        return;
                }
-               
+
                $filename = "$wgLocalMessageCache/messages-$wgDBname";
+               $oldUmask = umask( 0 );
                wfMkdirParents( $wgLocalMessageCache, 0777 );
+               umask( $oldUmask );
 
                $file = fopen( $filename, 'w' );
                if ( !$file ) {
@@ -108,6 +110,7 @@ class MessageCache
 
                fwrite( $file, $hash . $serialized );
                fclose( $file );
+               @chmod( $filename, 0666 );
        }
 
 
@@ -117,7 +120,7 @@ class MessageCache
         * Returns false for a reportable error, true otherwise
         */
        function load() {
-               global $wgAllMessagesEn, $wgLocalMessageCache;
+               global $wgLocalMessageCache;
 
                if ( $this->mDisable ) {
                        static $shownDisabled = false;
@@ -148,7 +151,7 @@ class MessageCache
                                $this->mCache = $this->mMemc->get( $this->mMemcKey );
 
                                # Save to local cache
-                               if ( $wgLocalMessageCache !== false ) { 
+                               if ( $wgLocalMessageCache !== false ) {
                                        $serialized = serialize( $this->mCache );
                                        if ( !$hash ) {
                                                $hash = md5( $serialized );
@@ -181,7 +184,7 @@ class MessageCache
                                        }
 
                                        # Save to local cache
-                                       if ( $wgLocalMessageCache !== false ) { 
+                                       if ( $wgLocalMessageCache !== false ) {
                                                $serialized = serialize( $this->mCache );
                                                $hash = md5( $serialized );
                                                $this->mMemc->set( "{$this->mMemcKey}-hash", $hash, $this->mExpiry );
@@ -225,7 +228,7 @@ class MessageCache
         */
        function loadFromDB() {
                global $wgAllMessagesEn, $wgLang;
-               
+
                $fname = 'MessageCache::loadFromDB';
                $dbr =& wfGetDB( DB_SLAVE );
                if ( !$dbr ) {
@@ -245,7 +248,7 @@ class MessageCache
                }
 
                # Negative caching
-               # Go through the language array and the extension array and make a note of 
+               # Go through the language array and the extension array and make a note of
                # any keys missing from the cache
                foreach ( $wgAllMessagesEn as $key => $value ) {
                        $uckey = $wgLang->ucfirst( $key );
@@ -258,7 +261,7 @@ class MessageCache
                        if ( !array_key_exists( $uckey, $this->mCache ) ) {
                                $this->mCache[$uckey] = false;
                        }
-               }       
+               }
 
                $dbr->freeResult( $res );
        }
@@ -286,16 +289,17 @@ class MessageCache
        }
 
        function replace( $title, $text ) {
-               global $wgLocalMessageCache;
+               global $wgLocalMessageCache, $parserMemc, $wgDBname;
 
                $this->lock();
                $this->load();
+               $parserMemc->delete("$wgDBname:sidebar");
                if ( is_array( $this->mCache ) ) {
                        $this->mCache[$title] = $text;
                        $this->mMemc->set( $this->mMemcKey, $this->mCache, $this->mExpiry );
-                       
+
                        # Save to local cache
-                       if ( $wgLocalMessageCache !== false ) { 
+                       if ( $wgLocalMessageCache !== false ) {
                                $serialized = serialize( $this->mCache );
                                $hash = md5( $serialized );
                                $this->mMemc->set( "{$this->mMemcKey}-hash", $hash, $this->mExpiry );
@@ -424,6 +428,9 @@ class MessageCache
                        }
                }
 
+               # Call message Hooks, in case they are defined
+               wfRunHooks('MessagesPreLoad',array($title,&$message));
+
                # If it wasn't in the cache, load each message from the DB individually
                $revision = Revision::newFromTitle( Title::makeTitle( NS_MEDIAWIKI, $title ) );
                if( $revision ) {
@@ -457,6 +464,8 @@ class MessageCache
        function enable() { $this->mDisable = false; }
        function disableTransform() { $this->mDisableTransform = true; }
        function enableTransform() { $this->mDisableTransform = false; }
+       function setTransform( $x ) { $this->mDisableTransform = $x; }
+       function getTransform() { return $this->mDisableTransform; }
 
        /**
         * Add a message to the cache